import React, { Component } from 'react'

export default class RandomNum extends Component {
  state={
    num:0
  }
  handle=()=>{
    this.setState({
        num:Math.floor(Math.random()*3)
    })
  }
  shouldComponentUpdate(prevProps,nextState){
    console.log('nextState',nextState);
    console.log('prevState',this.state);
    return nextState.num!==this.state.num
  }
  render() {
    console.log('-------render----------');
    return (
      <div>
         <h2>{this.state.num}</h2>
         <button onClick={this.handle}>更新</button>
      </div>
    )
  }
}
